package com.jd.rapid.rpc.consumer.test;

import com.jd.rapid.rpc.client.RpcClient;
import com.jd.rapid.rpc.client.RpcFuture;
import com.jd.rapid.rpc.client.User;
import com.jd.rapid.rpc.client.User2;
import com.jd.rapid.rpc.client.proxy.RpcAsyncProxy;
import io.protostuff.Rpc;

import java.util.Queue;
import java.util.concurrent.ExecutionException;

public class ConsumerStarter {

    public static  void sync(){
        //都应该从zk拉去服务列表
        RpcClient rpcClient=new RpcClient();
        //触发链接
        rpcClient.initClient("127.0.0.1:8769",3000);
        //为接口创建代理对象JDK
        HelloService helloService=rpcClient.invokeSync(HelloService.class);
        //调用的时候会触发InvocationHandler invoke
        String result=helloService.hello("zhangsan3");
        System.out.println(result);
    }

    public static  void async() throws  InterruptedException, ExecutionException{
        //都应该从zk拉去服务列表
        RpcClient rpcClient=new RpcClient();
        rpcClient.initClient("127.0.0.1:8769",3000);
        RpcAsyncProxy proxy=rpcClient.invokeAsync(HelloService.class);
        RpcFuture future=proxy.call("hello","lisi4");
        RpcFuture future2= proxy.call("hello",new User2("001","wx"));
        Object result=future.get();
        Object result2=future2.get();
        System.out.println("result--"+result);
        System.out.println("result2--"+result2);
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        async();
    }
}
